<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for components\message-box\index.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../prettify.css" />
    <link rel="stylesheet" href="../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../index.html">all files</a> / <a href="index.html">components/message-box/</a> index.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">19.44% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>7/36</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/16</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/6</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">19.44% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>7/36</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import Vue from 'vue'
import DxMessageBox from './dx-message-box.vue'
import { merge, isVNode } from '@/utils/utils.js'
const defaultOptions = {
	visible: false, // 控制弹窗是否可见
	parentEleId: '', // 挂载的父元素的id
	showHeader: true,
	title: '',
	callback: null,
	message: '',
	modal: true,
	// 按钮设置
	cancelBtnText: '取消',
	confirmBtnText: '确认',
	showBtns: true,
	showConfirm: true,
	showCancel: true,
	showClose: true,
	// 自定义样式
	customBoxClass: '',
	buttonClass: '',
	cancelButtonClass: '',
	confirmButtonClass: '',
	titleClass: '',
	contentClass: '',
	center: false
}
// 构建构造函数
const MessageConstructor = Vue.extend(DxMessageBox)
let currentOptions, instance
// let msgQueue = [];
// 默认回调函数
const defaultCallback = (action) =&gt; <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >	if (currentOptions) {</span>
		let callback = <span class="cstat-no" title="statement not covered" >currentOptions.callback</span>
<span class="cstat-no" title="statement not covered" >		if (typeof callback === 'function') {</span>
<span class="cstat-no" title="statement not covered" >			callback(action)</span>
		}
	}
}
let uniqueId = 1
// 初始化一个弹窗实例
const initInstance = () =&gt; <span class="fstat-no" title="function not covered" >{</span>
	let mountEl = <span class="cstat-no" title="statement not covered" >document.createElement('div')</span>
<span class="cstat-no" title="statement not covered" >	instance = new MessageConstructor({</span>
		el: mountEl
	})
<span class="cstat-no" title="statement not covered" >	instance.callback = defaultCallback</span>
}
// 打开弹窗
const OpenMessageBox = (options) =&gt; <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >	if (!instance) {</span>
<span class="cstat-no" title="statement not covered" >		initInstance()</span>
	}
<span class="cstat-no" title="statement not covered" >	if (!instance.visible) {</span>
<span class="cstat-no" title="statement not covered" >		currentOptions = merge({}, defaultOptions, options)</span>
		// 合并实例上的参数
<span class="cstat-no" title="statement not covered" >		merge(instance, currentOptions)</span>
<span class="cstat-no" title="statement not covered" >		if (!currentOptions.callback) {</span>
<span class="cstat-no" title="statement not covered" >			instance.callback = defaultCallback</span>
		}
		// 判断是否为自定义的内容vnode
<span class="cstat-no" title="statement not covered" >		if (isVNode(instance.message)) {</span>
			// 如果为vnode,则key设置不一样的可以以强制更新,否者vnode打补丁没更新
			// if (instance.message.tag.indexOf('vue-component') !== -1) {
<span class="cstat-no" title="statement not covered" >				instance.message.key = uniqueId = (uniqueId + 1) % 2</span>
			// }
<span class="cstat-no" title="statement not covered" >			instance.$slots.default = [instance.message]</span>
			// 如果自定义传入vnode，则会触发视图更新，从而渲染视图--注意视图渲染是异步更新的
			// 所以必须把message设置为null,支持视图还没有更新，否则会出现json解析错误
<span class="cstat-no" title="statement not covered" >			instance.message = null</span>
		} else {
<span class="cstat-no" title="statement not covered" >			delete instance.$slots.default</span>
		}
		let oldCb = <span class="cstat-no" title="statement not covered" >instance.callback</span>
<span class="cstat-no" title="statement not covered" >			instance.callback = (action, instance) =&gt; <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >			oldCb(action, instance)</span>
		}
      // 设置挂载元素
<span class="cstat-no" title="statement not covered" >      if (instance.parentEleId) {</span>
<span class="cstat-no" title="statement not covered" >			document.getElementById(instance.parentEleId).appendChild(instance.$el)</span>
      } else {
<span class="cstat-no" title="statement not covered" >			document.body.appendChild(instance.$el)</span>
      }
<span class="cstat-no" title="statement not covered" >      Vue.nextTick(() =&gt; <span class="fstat-no" title="function not covered" >{</span></span>
<span class="cstat-no" title="statement not covered" >        instance.visible = true</span>
      })
	}
}
OpenMessageBox.close = () =&gt; <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >	instance.visible = false</span>
<span class="cstat-no" title="statement not covered" >	instance.callback &amp;&amp; instance.callback('cancel', instance)</span>
	// currentOptions = null
}
export default OpenMessageBox
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Feb 24 2019 15:08:50 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>
